package com.HospitalOutpatient.service.impl;

import com.HospitalOutpatient.dao.DepartmentDao;
import com.HospitalOutpatient.entity.Department;
import com.HospitalOutpatient.service.DepartmentService;
import com.HospitalOutpatient.vo.DepartmentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("departmentService")
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentDao departmentDao;
    @Override
    public List<Department> getAllDepartment() {
        return departmentDao.selectAllDepartment();
    }

    @Override
    public boolean addDepartment(Department department) {
        int i = departmentDao.insertDepartment(department);
        return i == 1;
    }

    @Override
    public boolean editDepartment(Department department) {
        int i = departmentDao.updateDepartment(department);
        return i == 1;
    }

    @Override
    public List<DepartmentVo> getChooseDepartmentList() {
        List<DepartmentVo> departmentVoList = new ArrayList<>();

        List<Department> departmentList = departmentDao.selectAllDepartment();
        for (Department department : departmentList) {
            DepartmentVo departmentVo = new DepartmentVo();
            departmentVo.setValue(department.getDepartmentId());
            departmentVo.setLabel(department.getDepartmentName());
            departmentVoList.add(departmentVo);
        }
        return departmentVoList;
    }
}
